<template>
    <div class="setIndex">
        <div class="header">
            <van-nav-bar title="设置" left-arrow @click-left="handleLeft" />
        </div>
        <div class="setIndex_box">
            <div class="setIndex_form">
                <!-- <div class="setIndex_box_item" @click="isSetInformation = true">
                    <div class="label">消息设置</div>
                    <img src="@/assets/operation/icon_huisejiantou.png" alt="">
                </div> -->
                <div class="setIndex_box_item" @click="routerTo('/editPassword')">
                    <div class="label">修改密码</div>
                    <img src="@/assets/operation/icon_huisejiantou.png" alt="">
                </div>
                <div class="setIndex_box_item" @click="routerTo('/aboutMe')">
                    <div class="label">关于我们</div>
                    <img src="@/assets/operation/icon_huisejiantou.png" alt="">
                </div>
                <div class="setIndex_box_item" @click="routerTo('/policy')">
                    <div class="label">隐私政策</div>
                    <img src="@/assets/operation/icon_huisejiantou.png" alt="">
                </div>
                <div class="setIndex_box_item" @click="routerTo('/userAgreement')">
                    <div class="label">用户协议</div>
                    <img src="@/assets/operation/icon_huisejiantou.png" alt="">
                </div>
                <div class="setIndex_box_item" @click="logoff">
                    <div class="label">注销账号</div>
                    <img src="@/assets/operation/icon_huisejiantou.png" alt="">
                </div>
            </div>
            <div class="setIndex_out" @click="handleLogout" v-throttle:click>
                <img src="@/assets/porduct/quit.png" alt="">退出登录
            </div>
        </div>
        <SetInformation v-if="isSetInformation" @close="isSetInformation = false" />
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { getInfo } from "@/api/supplierList/index";
import { apiLogout, cancel } from '@/api/loginApi'
import { loginStore } from '@/store/login'
import { showConfirmDialog, showSuccessToast } from "vant";
import SetInformation from './setInformation.vue'

const router = useRouter()
const login = loginStore()
const userInfo = ref<any>({});
const roles = ref<any>({});
const isSetInformation = ref(false)


const getList = async () => {
    const res = await getInfo();
    roles.value = res.data.user.roles[0];
    userInfo.value = res.data.user;
};
getList();
// 返回
const handleLeft = () => {
    router.back()
}

// 退出账号
const handleLogout = () => {
    showConfirmDialog({
        message: "是否确认退出账号",
    }).then(async () => {
        const res = await apiLogout();
        if (res.code === 200) {
            login.resetToken();
            router.push("/login");
        }
    });
}

// 路由跳转
const routerTo = (url: string) => {
    router.push({
        path: url
    })
}

/** 注销 */
const logoff = async () => {
    showConfirmDialog({
        message: "是否确认注销账号",
    }).then(async () => {
        const res = await cancel({ userId: userInfo.value.userId })
        if (res.code === 200) {
            showSuccessToast('注销账号成功');
            login.resetToken();
            router.push("/login");
        }
    });
}
</script>

<style lang="less" scoped>
.setIndex {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-flow: column;

    .header {
        background: linear-gradient(#CDECFF 0%, #FFFFFF 70%);
        filter: blur(0px);
        height: 90px;
        padding-top: 44px;
        box-sizing: border-box;

        :deep(.van-icon-arrow-left) {
            color: #1a1b1c !important;
        }

        :deep(.van-nav-bar) {
            background: none !important;
        }

        :deep(.van-nav-bar__content) {
            background-color: transparent !important;
        }
    }

    .setIndex_box {
        flex: 1;
        min-height: 0;
        padding: 0 15px 40px;
        box-sizing: border-box;
        display: flex;
        flex-flow: column;
        justify-content: space-between;

        .setIndex_box_item {
            width: 100%;
            padding: 20px 0;
            box-sizing: border-box;
            border-bottom: 1px solid #FAFAFF;
            display: flex;
            align-items: center;
            justify-content: space-between;

            .label {
                font-weight: 400;
                font-size: 16px;
                color: #1B1D1E;
            }

            img {
                width: 7px;
                height: 12px;
            }
        }

        .setIndex_out {
            width: 345px;
            height: 44px;
            background: #FDE7E7;
            border-radius: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 400;
            font-size: 14px;
            color: #FC2540;

            img {
                width: 14px;
                height: 14px;
                margin-right: 10px;
            }
        }
    }
}
</style>